﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace delge_squirreleditor
{
    /// <summary>
    /// Interaction logic for Dialog_NewFile.xaml
    /// </summary>
    public partial class Dialog_NewFile : Window
    {
        ObservableCollection<FileType> _FileTypes = new ObservableCollection<FileType>();

        public ObservableCollection<FileType> FileTypes { get { return _FileTypes; } }

        public string SelectedFileTypeName { get { return (listviewFileType.SelectedItem as FileType).FileTypeName; } }
        public string Filename 
        { 
            get { return textboxFilename.Text; }
            set { textboxFilename.Text = value; }
        }

        public Dialog_NewFile()
        {
            _FileTypes.Add(new FileType { FileTypeName = "Screen", FileDescription = "Add a screen to your game." });
            _FileTypes.Add(new FileType { FileTypeName = "Class", FileDescription = "Add a class to your game." });
            _FileTypes.Add(new FileType { FileTypeName = "Script", FileDescription = "Add a basic script to your game." });

            InitializeComponent();

            listviewFileType.SelectedIndex = 0;
        }

        protected bool IsVaildFileName()
        {
            if (Filename.Length <= 0)
            {
                System.Windows.MessageBox.Show("Please enter a file name", "Delge Squirrel Editor", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }
            if (Filename.Length > Project.MaxFilenameLength)
            {
                System.Windows.MessageBox.Show("File name to long, please shorten it (Can be no longer than 25 characters)", "Delge Squirrel Editor", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

            return true;
        }

        public void buttonCreate_Click(object sender, RoutedEventArgs e)
        {
            if (IsVaildFileName())
                DialogResult = true;       
        }

        private void listviewFileType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (SelectedFileTypeName)
            {
                case "Screen": Filename = "myScreen"; break;
                case "Class": Filename = "myClass"; break;
                case "Script": Filename = "myScript"; break;
            }
        }
    }

    public class FileType
    {
        public string FileTypeName { get; set; }
        public string FileDescription { get; set; }
    }
}
